﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Contributor.Data_Objects;

namespace Contributor
{

    public class Utility
    {

        public static void TraceMsg(string msg)
        {
            //((MainPage)Application.Current.RootVisual).TraceMsg(msg);
        }

        public static void TraceMsg(string format, params object[] args)
        {
            TraceMsg(string.Format(format, args));
        }


        public static void BuildCommentBlock(DevExpress.Xpf.LayoutControl.LayoutGroup CommentBox, Entity entity)
        {
            CommentBox.Children.Clear();
            if (entity.Notes != null)
            {
                foreach (Note note in entity.Notes)
                {

                    CommentBox.Children.Add(new TextBlock()
                    {
                        Text = note.NoteDate==DateTime.MinValue ? string.Format("{0} -------", note.UserName) : string.Format("{0} {1:yyyy.MM.dd hh:mm}", note.UserName, note.NoteDate)
                    });

                    CommentBox.Children.Add(new TextBlock()
                    {
                        Text = note.NoteText,
                        Margin = new Thickness(10, 0, 0, 0) ,
                        MaxWidth = 400 ,
                        TextWrapping = TextWrapping.Wrap
                    });

                }
            }
        }

    }

    public class ColorValueConverter : System.Windows.Data.IValueConverter 
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        { 
            return new SolidColorBrush((bool)value ? Colors.Black : Colors.Gray);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        {
            return null;
        }

    }

    /*
    public class ResponsibleColorConverter : System.Windows.Data.IValueConverter 
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        {
            if (value is CashRequest)
            {
                CashRequest request = (CashRequest)value;
                if ( request.IsLocked )
                    return new SolidColorBrush(Color.FromArgb(0xBC,0xC7,0x4A,0x4A));  // pale red
                if ( request.IsUserResponsible )
                    return new SolidColorBrush(Color.FromArgb(0x90,0x62,0xAE,0x60));  // pale green
            }
            return new SolidColorBrush(Colors.White);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        {
            return null;
        }

    }
    */


    /// <summary>
    /// Used in Departments to display a forground in the list box of users
    /// If the user is authorized then we want to highlight the forground with red
    /// If the user is admin then we want to highlight the forground with blue
    /// If the user has both then we use a red/blue gradient
    /// </summary>
    /*
    public class UserAuthColorConverter : System.Windows.Data.IValueConverter 
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        {

            bool IsAdmin = false;
            bool IsAuthorized = false;

            if (value is CashRequestDeptUser)
            {
                CashRequestDeptUser user = value as CashRequestDeptUser;
                IsAuthorized = user.IsAuthorized;
                //IsAdmin = user.IsAdmin;
            }
            else if (value is CashRequestUser)
            {
                CashRequestUser user = value as CashRequestUser;
                IsAdmin = user.IsAdmin;
            }

            if (IsAdmin && IsAuthorized)
            {
                LinearGradientBrush brush = new LinearGradientBrush() 
                { 
                    StartPoint = new Point(0, 0), 
                    EndPoint = new Point(1, 1) 
                };
                brush.GradientStops.Add(new GradientStop() { Color = Colors.Blue, Offset = 0 });
                brush.GradientStops.Add(new GradientStop() { Color = Colors.Red, Offset = 1 });
                return brush;
            }

            if (IsAdmin) return new SolidColorBrush(Colors.Blue);

            if (IsAuthorized) return new SolidColorBrush(Colors.Red);

            return new SolidColorBrush(Colors.Black);
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) 
        {
            return null;
        }

    }
    */
}
